
package Ex2;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class WebsiteReader {

    
    public static BufferedReader read(String url) throws Exception{
		return new BufferedReader(
			new InputStreamReader(
				new URL(url).openStream()));}

	public static void main (String[] args) throws Exception{
		BufferedReader reader = read("http://vnexpress.net/Service/forex_content.js");
		String line = reader.readLine();
                List<Gia> list = new ArrayList<Gia>();
                while(line!= null)
                {
                    line = reader.readLine();
                    String str = "vForexs\\[\\d+\\].+=\\s'(.+)';.+vCosts\\[\\d+\\].+'([\\d\\.]+)';";
                    Pattern p = Pattern.compile(str);
                    Matcher m = p.matcher(line);
                    if(m.find())
                    {
                        Gia g = new Gia(m.group(1), m.group(2));
                        list.add(g);
                    }
                }
		//while (line != null) {
			//System.out.println(line);
			//line = reader.readLine(); }}
    }
}
